package com.ityj.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ityj.yygh.model.user.UserInfo;
import com.ityj.yygh.result.Result;
import com.ityj.yygh.user.service.UserInfoService;
import com.ityj.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(value = "用户管理")
@RestController
@RequestMapping(path = "/admin/user")
@Slf4j
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "用户列表")
    @GetMapping(path = "/{page}/{limit}")
    public Result<Object> listHospitalInfo(@PathVariable("page") Integer page,
                                           @PathVariable("limit") Integer limit,
                                           UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> userInfoPage = userInfoService.searchUserInfoByCondition(userInfoQueryVo, pageParam);
        return Result.ok(userInfoPage);
    }

    @ApiOperation(value = "用户锁定功能")
    @GetMapping(path = "/lock/{userId}/{status}")
    public Result<Object> lock(@PathVariable("userId") Long userId,
                               @PathVariable("status") Integer status) {
        userInfoService.updateStatus(userId, status);
        return Result.ok();
    }

    @ApiOperation(value = "用户详情信息")
    @GetMapping(path = "/showDetail/{userId}")
    public Result<Map<String, Object>> showDetail(@PathVariable("userId") Long userId) {
        Map<String, Object> result = userInfoService.getUserDetail(userId);
        return Result.ok(result);
    }

    @ApiOperation(value = "用户审批功能")
    @GetMapping(path = "/approval/{userId}/{authStatus}")
    public Result<Object> approve(@PathVariable("userId") Long userId, @PathVariable("authStatus") Integer authStatus) {
        userInfoService.approve(userId, authStatus);
        return Result.ok();
    }

}

